//
//  StarFileViewController.m
//  LiveStar
//
//  Created by 漪珊 on 2017/5/9.
//  Copyright © 2017年 apple. All rights reserved.
//

#import "StarFileViewController.h"
#import "StarFileCell.h"

@interface StarFileViewController ()<UITableViewDelegate,UITableViewDataSource>{
    NSMutableDictionary *_dataDict;
}
@property (nonatomic, strong) UITableView *tableView;
@end

@implementation StarFileViewController

#pragma mark -- 网络请求
- (void)StarFileRequestWithUserType:(UserType)userType {
    NSDictionary *dict;
    NSString *urlString;
    if (self.userType == UserTypeFans) {//粉丝
        dict = @{@"udid":User_ID,
                 @"token":TOKEN,
                 @"suid":self.s_uid
                 };
        urlString = [TEST_URL stringByAppendingString:kFStarFile];
    } else { //明星
        dict = @{@"udid":User_ID,
                 @"token":TOKEN,
                 };
        urlString = [TEST_URL stringByAppendingString:kStarFile];
    }
    [NetworkTools postReqeustWithParams:dict UrlString:urlString successBlock:^(id responseObject) {
        if ([responseObject[@"code"] intValue] == 200) {
            _dataDict = responseObject[@"data"];
            [self creatTableView];
        }
        [self.tableView reloadData];
    } failureBlock:^(NSError *error) {
        
    } showHUD:NO];
}

- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationItem.title = self.name;
    [self setUpUI];
    [self StarFileRequestWithUserType:self.userType];
    
}

#pragma mark -- UI
- (void)setUpUI {
    _dataDict = [NSMutableDictionary dictionaryWithCapacity:1];
    //tableView
    
    
}

- (void)creatTableView {
    self.tableView = [[UITableView alloc] initWithFrame:self.view.bounds];
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    self.tableView.backgroundColor = [UIColor whiteColor];
    self.tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero];
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    [self.view addSubview:self.tableView];
}

#pragma mark -- tableView 代理方法
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 6;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    StarFileCell *cell = [StarFileCell loadNibCellWithTabelView:tableView];
    switch (indexPath.row) {
        case 0:
            cell.titleLabel.text = @"中 文 名";
            cell.introduceLabel.text = [_dataDict[@"s_name"] isEqual:[NSNull null]]?@"":_dataDict[@"s_name"];
            break;
        case 1:
            cell.titleLabel.text = @"粉 丝 名";
            cell.introduceLabel.text = [_dataDict[@"u_nickname"] isEqual:[NSNull null]]?@"":_dataDict[@"u_nickname"];
            break;

        case 2:
            cell.titleLabel.text = @"星    座";
            cell.introduceLabel.text = [_dataDict[@"u_nickname"] isEqual:[NSNull null]]?@"":_dataDict[@"s_astro"];;
            break;

        case 3:
            cell.titleLabel.text = @"出 生 地";
            cell.introduceLabel.text = [_dataDict[@"u_nickname"] isEqual:[NSNull null]]?@"":_dataDict[@"s_born"];;
            break;
        case 4:
            cell.titleLabel.text = @"代表作品";
            cell.introduceLabel.text = [_dataDict[@"u_nickname"] isEqual:[NSNull null]]?@"":_dataDict[@"s_works"];;
            break;
        case 5:
            cell.titleLabel.text = @"主要成就";
            cell.introduceLabel.text = [_dataDict[@"u_nickname"] isEqual:[NSNull null]]?@"":_dataDict[@"s_record"];
            break;
        default:
            break;
    }
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
}

#pragma mark -- 区头视图
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
//    switch (indexPath.row) {
//        case 0:
//            return [self cellHeightWithText:];
//            break;
//        case 1:
//            return [self cellHeightWithText:_dataDict[@"u_nickname"]];
//            break;
//        case 2:
//            return [self cellHeightWithText:_dataDict[@"大狗座"]];
//            break;
//        case 3:
//            return [self cellHeightWithText:_dataDict[@"u_province"]];
//            break;
//        case 4:
//            return [self cellHeightWithText:@"分担塞饭东拉肯就开懂啊劳烦开发两腮翻了翻冬季风兰妃戳冬季风两腮"];
//            break;
//        case 5:
//            return [self cellHeightWithText:@"将来发动拉风扥额外肯激动凯发动机浪费老单老店分梁家乐福卡没带肯开动门老东家傅老大带肯借开动几番董凯反而歘哦可安迪FM开三方窗肯将所犯拆了"];
//            break;
//            
//        default:
//            break;
//    }
    return 50;
}

- (CGFloat)cellHeightWithText:(NSString *)text {
    CGSize maxSize = CGSizeMake(kSCREEN_WIDTH - 135, CGFLOAT_MAX);
    NSDictionary *attributes = @{NSFontAttributeName: [UIFont systemFontOfSize:14]};
    CGSize textSize = [text boundingRectWithSize:maxSize options:NSStringDrawingUsesLineFragmentOrigin attributes:attributes
                                                         context:nil].size;
    return textSize.height;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
